using System;
using System.Windows.Threading;

namespace WindowsPhoneEssentials.Threading
{
    public static class DelayedDispatcher
    {
        public static void BeginInvoke(TimeSpan inSeconds, Action action)
        {
            var executed = false;
            var timer = new DispatcherTimer {Interval = inSeconds};
            timer.Tick += (sender, e) =>
                              {
                                  if (executed) return;
                                  executed = true;
                                  timer.Stop();
                                  action();
                              };
            timer.Start();
        }
    }
}